<?php
declare(strict_types=1);

/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

use Newbie\Annotation\Bootstrap\AnnotationBootstrap;
use Newbie\Annotation\Parser\RouteAnnotationParser;
use support\Request;
use Webman\Route;

Route::get('/hello', function () {
    return response('ok');
});
//请求不存在的url返回信息
Route::fallback(function (Request $request) {
    $origin = $request->header('origin');
    if (!$origin) {
        $origin = 'http://localhost:5173';
    }
    $headers  = [
        'Access-Control-Allow-Credentials' => 'true',
        'Access-Control-Allow-Origin'      => $request->header('origin', $origin),
        'Access-Control-Allow-Methods'     => $request->header('access-control-request-method', '*'),
        'Access-Control-Allow-Headers'     => $request->header('access-control-request-headers', '*'),
    ];
    $response = strtoupper($request->method()) === 'OPTIONS' ? response('', 204) : json(['code' => 404, 'message' => 'url error', 'success' => false]);
    return $response->withHeaders($headers);
});

if (!AnnotationBootstrap::isIgnoreProcess()) {
    RouteAnnotationParser::createRoute();
}
// 关闭默认路由放在最后
Route::disableDefaultRoute();




